package cn.bs.busuo.content.controller;

import cn.bs.busuo.common.pojo.authentication.CurrentPrincipal;
import cn.bs.busuo.common.web.JsonResult;
import cn.bs.busuo.content.pojo.vo.CommentHotelByCheckVO;
import cn.bs.busuo.content.service.CommentService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/content")
@Api(tags = "3.评论管理")
public class CommentController {

    @Autowired
    private CommentService commentService;

    //-----------酒店部分
    @GetMapping("/listHotelNotCheck")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("查看未审核的酒店文章评论")
    @ApiOperationSupport(order = 100)
    public JsonResult listHotelNotCheck(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        return JsonResult.ok(commentService.listHotelNotCheck());
    }


    @PostMapping("/hotelCheck") // 路径不加变量原因:前端获取未审核评论封装到一个个卡片里面,未审核的评论数据是一个数组,然后可以获取未审核评论ID,封装到一个按钮,通过按钮传过来这个id参数
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("审核酒店文章评论通过")
    @ApiOperationSupport(order = 200)
    public JsonResult hotelCommentCheck(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        commentService.hotelCommentCheck(ids);
        return JsonResult.ok();
    }

    @PostMapping("/hotelNotCheck")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("审核酒店文章评论不通过")
    @ApiOperationSupport(order = 300)
    public JsonResult hotelCommentNotCheck(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        commentService.hotelCommentNotCheck(ids);
        return JsonResult.ok();
    }




    //-----------景点部分



    @GetMapping("/listSightNotCheck")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("查看未审核的景点文章评论")
    @ApiOperationSupport(order = 600)
    public JsonResult listSightNotCheck(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        return JsonResult.ok(commentService.listSightNotCheck());
    }

    @PostMapping("/sightCheck")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ResponseBody
    @ApiOperation("审核景点文章评论通过")
    @ApiOperationSupport(order = 700)
    public JsonResult sightCommentCheck(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        commentService.sightCommentCheck(ids);
        return JsonResult.ok();
    }

    @PostMapping("/sightNotCheck")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("审核景点文章评论不通过")
    @ApiOperationSupport(order = 800)
    public JsonResult sightCommentNotCheck(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        commentService.sightCommentNotCheck(ids);
        return JsonResult.ok();
    }
}
